package wangjg.android.uitest;

import wangjg.android.BasicActivity;
import wangjg.android.R;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.LinearLayout;
import android.widget.Toast;

public class GalleryActivity extends BasicActivity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gallery);

		Gallery gallery = (Gallery) findViewById(R.id.gallery);
		// 定义 Gallery 控件
		 gallery.setAdapter(new BaseAdapter(){
			@Override
			public int getCount() {
				return 3;
			}

			@Override
			public Object getItem(int position) {
				return position;
			}

			@Override
			public long getItemId(int position) {
				return position;
			}

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				View v = GalleryActivity.this.inflate(R.layout.xx);
				Log.d("vv",v.getClass().getName());
				LinearLayout ll = (LinearLayout) v.findViewById(R.id.imageViewLL);
				ll.setLayoutParams(new LinearLayout.LayoutParams(300, 400));//a
				v.setLayoutParams(new Gallery.LayoutParams(300, 400));//b (a/b二选一)
				
				v.findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
					public void onClick(View v) {
						Toast.makeText(GalleryActivity.this, "button click",Toast.LENGTH_LONG).show();
					}  
			    });
				return v;
			}
			 
		 });

		gallery.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView parent, View v, int position,long id) {// 点击事件
				Toast.makeText(GalleryActivity.this, "Gallery position:" + position, Toast.LENGTH_SHORT).show(); // Toast显示图片位置
			}
		});
	}

}